﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" 
CodeBehind="NewspaperAdmin.aspx.cs" Inherits="Nivdal.NewspaperAdmin" Theme="SkinFile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadPlaceHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Panel ID="NewspaperDirPanel" runat="server">
        <div class="basic_element">
        <div class="red_title">
           <asp:Label ID="PageTitleLabel" runat="server" Text="<%$ Resources:Resource, Newspaper_PageName %>" CssClass="white_title"></asp:Label>
        </div>
        <div class="padding5">

        
        <table style="width:100%;" cellpadding="0" cellspacing="0">
        <tr>
        <td style="vertical-align:top; width:70%;">
            
            <asp:HiddenField ID="NewspaperIdHiddenField" runat="server" />
            <asp:DropDownList ID="NewspapersDDL" runat="server" DataSourceID="NewspapersDataSourse" DataTextField="Name" DataValueField="Id"
             OnSelectedIndexChanged="RedirectToNewspaper" AutoPostBack="true">        
            </asp:DropDownList>
            <asp:SqlDataSource ID="NewspapersDataSourse" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="Nivdal_GetUserEditorNewspapers" SelectCommandType="StoredProcedure">
            </asp:SqlDataSource>
            <br /> <hr /><br /> 
            <asp:UpdatePanel ID="NewspaperNamePanel" runat="server" UpdateMode="Conditional">
            <ContentTemplate> 
      
            <asp:FormView ID="NewsPaperNameFormView" runat="server" DataSourceID="NewsPaperTopStoriesDataSource">
                <EditItemTemplate>
                    <asp:Label ID="NewsPaperNameTitleLabel" runat="server" Text="<%$ Resources:Resource, NewspaperAdmin_NewspaperName %>" SkinID="InfoLabel"></asp:Label>
                    <br />
                    <asp:TextBox ID="NewspaperNameTextBox" runat="server" Text='<%# Bind("NewspaperName") %>' Width="300" MaxLength="256" ></asp:TextBox>
                    <asp:Button ID="UpdateButton" runat="server" Text="<%$ Resources:Resource, Global_Update %>" CssClass="GreenSmallButtonStyle" 
                     CommandName="Update" />
                     <asp:Button ID="CancelButton" runat="server" Text="<%$ Resources:Resource, Global_Cancel %>" CssClass="GreySmallButtonStyle" 
                     CommandName="Cancel" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="NewsPaperNameTitleLabel" runat="server" Text="<%$ Resources:Resource, NewspaperAdmin_NewspaperName %>" SkinID="InfoLabel"></asp:Label>
                    <br />
                    <asp:Label ID="NewspaperNameLabel" runat="server" Text='<%# Eval("NewspaperName") %>' SkinID="GridLabel"></asp:Label>
                    <br />
                    <asp:Button ID="EditButton" runat="server" Text="<%$ Resources:Resource, Global_Edit %>" CssClass="GreenSmallButtonStyle" 
                     CommandName="Edit" />
                </ItemTemplate>
            </asp:FormView>
            </ContentTemplate>
            </asp:UpdatePanel>
            <br />
            <asp:UpdatePanel ID="SendMessagePanel" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Label ID="SendMessageToWritersTitleLabel" runat="server" SkinID="InfoLabel"
                 Text="<%$ Resources:Resource, NewspaperAdmin_SendMessageToWriterstitle %>"></asp:Label>
                 <br />
                <asp:Label ID="MessageToWritersTitleLabel" runat="server" Text="<%$ Resources:Resource, Global_Title %>" SkinID="InfoLabel"></asp:Label>
                <br />
                <asp:TextBox ID="MessageToWritersTitleTextBox" runat="server" MaxLength="255" Width="250" TextMode="SingleLine"></asp:TextBox>
                <br /><br />
                <asp:Label ID="MessageLabel" runat="server" Text="<%$ Resources:Resource, ComposeMail_MessageLabel %>" SkinID="InfoLabel"></asp:Label> 
                <br />
                <CustomControls:TextArea ID="MessageToWritersBox" runat="server" TextMode="MultiLine" MaxLength="1000" Width="350" Height="80"></CustomControls:TextArea>
                <asp:Button ID="SendMessageToWritesButton" runat="server" OnClick="SendMessageToWriters" 
                  CssClass="GreenSmallButtonStyle" Text="<%$ Resources:Resource, Global_Send %>" />
                <br />
                <asp:Label ID="MessageSentLabel" runat="server" Text="<%$ Resources:Resource, azx4qaMM1qvPOTHJA %>"
                 SkinID="GreenSmallHeaderLabel" Visible="false"></asp:Label>
            </ContentTemplate>
            </asp:UpdatePanel>
            
        </td>
        <td  style="width:30%; text-align:center; vertical-align:top;">
            <asp:HyperLink ID="LogoImage" runat="server" ImageUrl="~/Images/NewsPaper/logo.jpg"
                NavigateUrl="~/NewsPaper.aspx"></asp:HyperLink>            
        </td>
        </tr>
        </table>
    
        
        </div>
        </div>
        <div class="basic_element">
        <div class="red_title">
           <asp:Label ID="StoriesPendingApprovalTitleLabel" runat="server" Text="<%$ Resources:Resource, NewspaperAdmin_ListOfStoriesPendingApproval %>" CssClass="white_title"></asp:Label>
        </div>
        <div class="padding5">
            <asp:GridView ID="StoriesPendingApprovalGridview" runat="server" DataSourceID="StoriesPendingApprovalDataSource" AllowPaging="false" SkinID="Professional"
             AutoGenerateColumns="false">
             <EmptyDataTemplate>
                 <asp:Label ID="NoStoriesToApprove" runat="server" SkinID="GridLabel"
                  Text="<%$ Resources:Resource, NewspaperAdmin_NoStoriesToApprove %>"></asp:Label>
             </EmptyDataTemplate>
             <Columns>
                <asp:TemplateField HeaderText="<%$ Resources:Resource, Global_Title %>">
                    <ItemTemplate>
                        <asp:HyperLink ID="StoryTitleHyperlink" runat="server" SkinID="BlackHyperLinkSkin" Text='<%# Eval("StoryTitle") %>'
                         NavigateUrl='<%# "~/Story.aspx?StoryId=" + Eval("StoryId") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="<%$ Resources:Resource, NewspaperAdmin_RubricNameTitle %>">
                    <ItemTemplate>
                        <asp:HyperLink ID="RubricHyperlink" runat="server" SkinID="BlackHyperLinkSkin" Text='<%# Eval("RubricName") %>'
                         NavigateUrl='<%# "~/Rubric.aspx?Id=" + Eval("RubricId") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="<%$ Resources:Resource, NewsPaper_StoryAuthorLabel %>">
                    <ItemTemplate>
                        <asp:HyperLink ID="AuthorHyperlink" runat="server" SkinID="GreenTitleHyperLink" Text='<%# Eval("AuthorName") %>'
                         NavigateUrl='<%# "~/UserPage.aspx?Id=" + Eval("AuthorId") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
             </Columns>
            </asp:GridView>
        </div>
        </div>
        
        <div class="basic_element">
        <div class="red_title">
           <asp:Label ID="ListOfRubricsTitleLabel" runat="server" Text="<%$ Resources:Resource, NewspaperAdmin_ListOfRubricsTitleLabelText %>" CssClass="white_title"></asp:Label>
        </div>
        <div class="padding5">
        
            <asp:UpdatePanel ID="RubricsUpdatePanel" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
    
                <asp:GridView ID="RubricsGridview" runat="server" AutoGenerateColumns="false" SkinID="Professional" AllowPaging="false" 
                DataSourceID="RubricsDataSourse" DataKeyNames="RubricId" >
                <EmptyDataTemplate>
    
                </EmptyDataTemplate>
                <Columns>
                    <asp:TemplateField>
                        <EditItemTemplate> 
                            <asp:HiddenField ID="rubricIdHiddenField" runat="server" Value='<%# Bind("RubricId") %>' />
                            <asp:TextBox ID="RubricNameTextbox" runat="server" Text='<%# Bind("RubricName") %>' MaxLength="256"></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="RubricNameLabel" runat="server" Text='<%# Eval("RubricName") %>' SkinID="GridLabel"></asp:Label>                
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="<%$ Resources:Resource, NewspaperAdmin_RubricDescription %>">
                        <ItemTemplate>
                            <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' SkinID="GridLabel"></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <CustomControls:TextArea ID="DescriptionTextbox" runat="server" Text='<%# Bind("Description") %>' TextMode="MultiLine"
                             MaxLength="1024" Height="50"></CustomControls:TextArea>
                        </EditItemTemplate>
            
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Button ID="EditButton" runat="server" Text="<%$ Resources:Resource, Global_Edit %>" CssClass="GreenSmallButtonStyle" CommandName="Edit" />
                            &nbsp;
                            <asp:ImageButton ID="DeleteButton" runat="server" ImageUrl="~/Images/Icons/delete.png" ToolTip="<%$ Resources:Resource, Global_Delete %>"
                             CommandName="Delete" Visible='<%# Eval("CanBeDeleted") %>' />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Button ID="UpdateButton" runat="server" Text="<%$ Resources:Resource, Global_Update %>" CssClass="GreenSmallButtonStyle" CommandName="Update" />
                            <asp:Button ID="CancelButton" runat="server" Text="<%$ Resources:Resource, Global_Cancel %>" CssClass="GreySmallButtonStyle" CommandName="Cancel" />                    
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Columns>
    
                </asp:GridView>
                <br />
                <asp:TextBox ID="AddNewRubricTextBox" runat="server" MaxLength="256" Width="300"></asp:TextBox>
                <asp:Button ID="AddRubricButton" runat="server" Text="<%$ Resources:Resource, Global_Add %>" CssClass="GreenSmallButtonStyle" 
                 OnClick="AddNewRubric" />
            </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        </div>
        <div class="basic_element">
        <div class="red_title">
           <asp:Label ID="UsersTitleLabel" runat="server" Text="<%$ Resources:Resource, NewspaperAdmin_ListOfUsersText %>" CssClass="white_title"></asp:Label>
        </div>
        <div class="padding5">
        <asp:UpdatePanel ID="UserPrevilagesUpdatePanel" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            
            <asp:Repeater ID="NewspaperWritersRepeater" runat="server" DataSourceID="NewspaperWritersDataSourse" OnItemCommand="UpdateWriter">
            <ItemTemplate>
                <table style="width:70%">
                <tr>
                <td style="width:80%;">
                    <asp:HiddenField ID="UserIdHiddenField" runat="server" Value='<%# Eval("UserId") %>' />
                    <asp:HyperLink ID="UserHyperlink" runat="server" Text='<%# Eval("PublicName") %>' 
                    NavigateUrl='<%# "~/UserPage.aspx?Id=" + Eval("UserId") %>' SkinID="GreenTitleHyperLink"></asp:HyperLink>
                    &nbsp;
                    <asp:Label ID="RoleLabel" runat="server" Text='<%# RoleString(Eval("Role")) %>' SkinID="InfoLabel"></asp:Label>
                    <br />
                    <asp:Label ID="RubricsPrivsLabel" runat="server" Text="<%$ Resources:Resource, NewspaperAdmin_RubricsPrivsTitle %>" SkinID="InfoLabel"></asp:Label>
                    <br />
                    <asp:GridView ID="RubricsGridView" runat="server" AutoGenerateColumns="false" AllowPaging="false" SkinID="Professional" DataSourceID="UserRubricsDataSource">
                    <Columns>
                        <asp:TemplateField>
                        <ItemTemplate>
                            <asp:HiddenField ID="RubricIdHiddenField" runat="server" Value='<%# Eval("RubricId") %>' />
                            <asp:CheckBox ID="PrivCheckBox" runat="server" Checked='<%# Eval("HasPrivs") %>' Text='<%# Eval("RubricName") %>' CssClass="NewsItemStyle"/>
                        </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    </asp:GridView>
                    <asp:SqlDataSource ID="UserRubricsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        SelectCommand="Nivdal_GetUserRubricsAccess" SelectCommandType="StoredProcedure">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="NewspaperIdHiddenField" PropertyName="Value" Name="NewspaperId" Type="Decimal" />
                            <asp:ControlParameter ControlID="UserIdHiddenField" PropertyName="Value" Name="UserId" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </td>
                <td style="vertical-align:bottom; width:20%;">
                    <asp:Label ID="UpdatedLabel" runat="server" Text="<%$ Resources:Resource, NewspaperAdmin_PrivilegesUpdated %>" SkinID="GreenSmallHeaderLabel" Visible="false"></asp:Label>
                    <asp:Button ID="UpdateButton" runat="server" Text="<%$ Resources:Resource, Global_Update %>" CssClass="GreenSmallButtonStyle" CommandArgument='<%# Eval("UserId") %>' />
                </td>
                </tr>
                </table>
                <br />
            </ItemTemplate>
            </asp:Repeater>        
        </ContentTemplate>
        </asp:UpdatePanel>
        </div>
        </div>
        
        <asp:SqlDataSource ID="NewspaperWritersDataSourse" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="Nivdal_GetNewspaperWriters" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="NewspaperIdHiddenField" PropertyName="Value" Name="NewspaperId" Type="Decimal" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="RubricsDataSourse" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="Nivdal_GetNewspaperRubricsForAdmin" SelectCommandType="StoredProcedure"
            UpdateCommand="Nivdal_UpdateRubricName" UpdateCommandType="StoredProcedure"
            DeleteCommand="Nivdal_DeleteRubric" DeleteCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="NewspaperIdHiddenField" PropertyName="Value" Name="NewspaperId" Type="Decimal" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="RubricId" Type="Decimal" />
            </DeleteParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="NewsPaperTopStoriesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="Nivdal_GetNewspaperName" SelectCommandType="StoredProcedure"
            UpdateCommand="Nivdal_UpdateNewspaperName" UpdateCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="NewspaperIdHiddenField" PropertyName="Value" Name="NewspaperId" Type="Decimal" />
            </SelectParameters>
            <UpdateParameters>
                <asp:ControlParameter ControlID="NewspaperIdHiddenField" PropertyName="Value" Name="NewspaperId" Type="Decimal" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="StoriesPendingApprovalDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="Nivdal_GetStoriesPendingApproval" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="NewspaperIdHiddenField" PropertyName="Value" Name="NewspaperId" Type="Decimal" />
            </SelectParameters>
        </asp:SqlDataSource>
     </asp:Panel>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageNamePlaceHolder" runat="server">
    <asp:Label ID="PageNameLabel" runat="server" Text="<%$ Resources:Resource, Newspaper_PageName %>" CssClass="PageNameContentStyle"></asp:Label>
</asp:Content>
